const batchRequest = (urlList, retryTime, callback) => {
    // 控制最大并发数量
    const maxRequest = 4;
    // 当前发出的数量
    let current = 0;
    // 记录结果
    const result = [];
    const waitList = [];
    let finishCount = 0;
    // 等待
    const wait = () => {
        return new Promise((resolve) => {
            waitList.push(resolve);
        });
    }
    // 执行下一个
    const next = () => {
        if (waitList.length > 0) {
            const resolve = waitList.shift();
            resolve();
        }
    }
    const run = async (url, i) => {
        // 达到并发数量
        if (current == maxRequest) {
            await wait();
        }

        let isSuccess = false;
        // 支持重发
        for (let i = retryTime; i > 0; i--) {
            // 成功后不发
            if (isSuccess) {
                next();
                break;
            }
            fetch(url).then((data) => {
                result[i] = data;
                isSuccess = true;
            }).catch((err) => {
                if (i == 1) {
                    result[i] = null;
                    isSuccess = true;
                }
            }).finally(() => {
                if (isSuccess) {
                    current--;
                    finishCount++;
                    if (finishCount == urlList.length) {
                        callback(result);
                    }
                }
            });
        }
    }

    urlList.forEach((url, index) => {
        run(url, index);
    })
}